package com.minglead.crawler.enums;

import cn.hutool.core.util.ObjectUtil;
import com.minglead.crawler.entity.SelectEntity;
import com.minglead.crawler.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public enum MacroRepoStatusEnum {
    YES("YES", "已入库"),
    NO("NO", "待入库");

    /** 枚举值 */
    private final String code;

    /** 枚举描述 */
    private final String description;

    /**
     * 构造方法
     * @param code
     * @param message
     */
    MacroRepoStatusEnum(String code, String message) {
        this.code = code;
        this.description = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return description;
    }

    public static MacroRepoStatusEnum getEnum(String code) {
        if (ObjectUtil.isNotNull(code)) {
            MacroRepoStatusEnum[] VALUES = MacroRepoStatusEnum.values();
            for (MacroRepoStatusEnum ele : VALUES) {
                if (StringUtils.equals(ele.code,code)) {
                    return ele;
                }
            }
        }
        return null;
    }

    public static String getDescription(String code) {
        if (ObjectUtil.isNotNull(code)) {
            MacroRepoStatusEnum[] VALUES = MacroRepoStatusEnum.values();
            for (MacroRepoStatusEnum ele : VALUES) {
                if (StringUtils.equals(ele.code,code)) {
                    return ele.description.toString();
                }
            }
        }
        return null;
    }

    /**
     * 获取下拉列表填充数据
     * @return 下拉列表填充数据
     */
    public static List<SelectEntity> getSelectList() {
        List<SelectEntity> result = new ArrayList<>();
        for (MacroRepoStatusEnum row :
                MacroRepoStatusEnum.values()) {
            SelectEntity data = new SelectEntity();
            data.setLabel(row.description);
            data.setVal(row.code);
            result.add(data);
        }
        return result;
    }
}